#include <stdlib.h>
#include <stdio.h>

int lim = 40000000;
int len = 25;

unsigned long sum = 0;

int
main(void)
{
        int *tot;
        int n, k;
        int prime;

        tot = malloc(lim*sizeof(int));
        for (n = 1; n < lim; n++)
                tot[n] = n;
        for (n = 2; n < lim; n++) {
                if (tot[n] == n) {
                        k = n;
                        while (k < lim) {
                                tot[k] -= tot[k]/n;
                                k += n;
                        }
                }
                if (tot[n] == n-1) {
                        prime = 1;
                } else {
                        prime = 0;
                }
                tot[n] = 1+tot[tot[n]];
                if (prime && tot[n] == len)
                        sum += n;
        }
        printf("sum: %lu\n", sum);
        return 0;
}
